472f389cef0a064ba8e34efe4377a35cbcb46f94,jt-warp/src/main/java/it/geosolutions/jaiext/warp/WarpBilinearOpImage.java,WarpBilinearOpImage,computeRectInt,#PlanarImage#RasterAccessor#ROI#,1150
Before Change
int lineOffset = 0;
// ONLY VALID DATA
if (caseA) {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
final float sx = warpData[count++];
final float sy = warpData[count++];
final int xint = floor(sx);
final int yint = floor(sy);
final float xfrac = sx - xint;
final float yfrac = sy - yint;
if (xint < minX || xint >= maxX || yint < minY || yint >= maxY) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
}
}
} else {
//
// NO ROI
//
for (int b = 0; b < dstBands; b++) {
int s00 = iterSource.getSample(xint, yint, b);
int s01 = iterSource.getSample(xint + 1, yint, b);
int s10 = iterSource.getSample(xint, yint + 1, b);
int s11 = iterSource.getSample(xint + 1, yint + 1, b);
float s0 = (s01 - s00) * xfrac + s00;
float s1 = (s11 - s10) * xfrac + s10;
float s = (s1 - s0) * yfrac + s0;
data[b][pixelOffset + bandOffsets[b]] = (int) s;
}
}
// next desination pixel
pixelOffset += pixelStride;
} // COLS LOOP
}
// ONLY ROI
} else if (caseB) {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
final float sx = warpData[count++];
final float sy = warpData[count++];
final int xint = floor(sx);
final int yint = floor(sy);
final float xfrac = sx - xint;
final float yfrac = sy - yint;
if (xint < minX || xint >= maxX || yint < minY || yint >= maxY) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
}
}
} else {
//
// ROI
//
// checks with roi
final boolean w00 = !roiTile.contains(xint, yint);
final boolean w01 = !roiTile.contains(xint + 1, yint);
final boolean w10 = !roiTile.contains(xint, yint + 1);
final boolean w11 = !roiTile.contains(xint + 1, yint + 1);
if (w00 && w01 && w10 && w11) { // SG should not happen
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
}
} else {
for (int b = 0; b < dstBands; b++) {
int s00 = iterSource.getSample(xint, yint, b);
int s01 = iterSource.getSample(xint + 1, yint, b);
int s10 = iterSource.getSample(xint, yint + 1, b);
int s11 = iterSource.getSample(xint + 1, yint + 1, b);
float s0 = (s01 - s00) * xfrac + s00;
float s1 = (s11 - s10) * xfrac + s10;
float s = (s1 - s0) * yfrac + s0;
data[b][pixelOffset + bandOffsets[b]] = (int) s;
}
}
}
// next desination pixel
pixelOffset += pixelStride;
} // COLS LOOP
} // ROWS LOOP
// ONLY NODATA
} else if (caseC) {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
final float sx = warpData[count++];
final float sy = warpData[count++];
final int xint = floor(sx);
final int yint = floor(sy);
final float xfrac = sx - xint;
final float yfrac = sy - yint;
if (xint < minX || xint >= maxX || yint < minY || yint >= maxY) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
}
}
} else {
//
// NODATA
//
// checks with nodata
for (int b = 0; b < dstBands; b++) {
int s00 = iterSource.getSample(xint, yint, b);
int s01 = iterSource.getSample(xint + 1, yint, b);
int s10 = iterSource.getSample(xint, yint + 1, b);
int s11 = iterSource.getSample(xint + 1, yint + 1, b);
final boolean w00 = noDataRange.contains(s00);
final boolean w01 = noDataRange.contains(s01);
final boolean w10 = noDataRange.contains(s10);
final boolean w11 = noDataRange.contains(s11);
if (w00 && w01 && w10 && w11) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
} else {
data[b][pixelOffset + bandOffsets[b]] = ((int) computePoint(s00,
s01, s10, s11, xfrac, yfrac, w00, w01, w10, w11));
}
}
}
// next desination pixel
pixelOffset += pixelStride;
} // COLS LOOP
} // ROWS LOOP
// BOTH ROI AND NODATA
} else {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
final float sx = warpData[count++];
final float sy = warpData[count++];
final int xint = floor(sx);
final int yint = floor(sy);
final float xfrac = sx - xint;
final float yfrac = sy - yint;
if (xint < minX || xint >= maxX || yint < minY || yint >= maxY) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
}
}
} else {
//
// ROI
//
// checks with roi
final boolean w00Roi = !roiTile.contains(xint, yint);
final boolean w01Roi = !roiTile.contains(xint + 1, yint);
final boolean w10Roi = !roiTile.contains(xint, yint + 1);
final boolean w11Roi = !roiTile.contains(xint + 1, yint + 1);
if (w00Roi && w01Roi && w10Roi && w11Roi) { // SG should not happen
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
After Change
int lineOffset = 0;
// ONLY VALID DATA
if (caseA || (caseB && roiContainsTile)) {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
final float sx = warpData[count++];
final float sy = warpData[count++];
final int xint = floor(sx);
final int yint = floor(sy);
final float xfrac = sx - xint;
final float yfrac = sy - yint;
if (xint < minX || xint >= maxX || yint < minY || yint >= maxY) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
}
}
} else {
//
// NO ROI
//
for (int b = 0; b < dstBands; b++) {
int s00 = iterSource.getSample(xint, yint, b);
int s01 = iterSource.getSample(xint + 1, yint, b);
int s10 = iterSource.getSample(xint, yint + 1, b);
int s11 = iterSource.getSample(xint + 1, yint + 1, b);
float s0 = (s01 - s00) * xfrac + s00;
float s1 = (s11 - s10) * xfrac + s10;
float s = (s1 - s0) * yfrac + s0;
data[b][pixelOffset + bandOffsets[b]] = (int) s;
}
}
// next desination pixel
pixelOffset += pixelStride;
} // COLS LOOP
}
// ONLY ROI
} else if (caseB) {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
final float sx = warpData[count++];
final float sy = warpData[count++];
final int xint = floor(sx);
final int yint = floor(sy);
final float xfrac = sx - xint;
final float yfrac = sy - yint;
if (xint < minX || xint >= maxX || yint < minY || yint >= maxY) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
}
}
} else {
//
// ROI
//
// checks with roi
final boolean w00 = !(roiIter.getSample(xint, yint, 0) > 0);
final boolean w01 = !(roiIter.getSample(xint + 1, yint, 0) > 0);
final boolean w10 = !(roiIter.getSample(xint, yint + 1, 0) > 0);
final boolean w11 = !(roiIter.getSample(xint + 1, yint + 1, 0) > 0);
if (w00 && w01 && w10 && w11) { // SG should not happen
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
}
} else {
for (int b = 0; b < dstBands; b++) {
int s00 = iterSource.getSample(xint, yint, b);
int s01 = iterSource.getSample(xint + 1, yint, b);
int s10 = iterSource.getSample(xint, yint + 1, b);
int s11 = iterSource.getSample(xint + 1, yint + 1, b);
float s0 = (s01 - s00) * xfrac + s00;
float s1 = (s11 - s10) * xfrac + s10;
float s = (s1 - s0) * yfrac + s0;
data[b][pixelOffset + bandOffsets[b]] = (int) s;
}
}
}
// next desination pixel
pixelOffset += pixelStride;
} // COLS LOOP
} // ROWS LOOP
// ONLY NODATA
} else if (caseC || (hasROI && hasNoData && roiContainsTile)) {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
final float sx = warpData[count++];
final float sy = warpData[count++];
final int xint = floor(sx);
final int yint = floor(sy);
final float xfrac = sx - xint;
final float yfrac = sy - yint;
if (xint < minX || xint >= maxX || yint < minY || yint >= maxY) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
}
}
} else {
//
// NODATA
//
// checks with nodata
for (int b = 0; b < dstBands; b++) {
int s00 = iterSource.getSample(xint, yint, b);
int s01 = iterSource.getSample(xint + 1, yint, b);
int s10 = iterSource.getSample(xint, yint + 1, b);
int s11 = iterSource.getSample(xint + 1, yint + 1, b);
final boolean w00 = noDataRange.contains(s00);
final boolean w01 = noDataRange.contains(s01);
final boolean w10 = noDataRange.contains(s10);
final boolean w11 = noDataRange.contains(s11);
if (w00 && w01 && w10 && w11) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
} else {
data[b][pixelOffset + bandOffsets[b]] = ((int) computePoint(s00,
s01, s10, s11, xfrac, yfrac, w00, w01, w10, w11));
}
}
}
// next desination pixel
pixelOffset += pixelStride;
} // COLS LOOP
} // ROWS LOOP
// BOTH ROI AND NODATA
} else {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
final float sx = warpData[count++];
final float sy = warpData[count++];
final int xint = floor(sx);
final int yint = floor(sy);
final float xfrac = sx - xint;
final float yfrac = sy - yint;
if (xint < minX || xint >= maxX || yint < minY || yint >= maxY) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;
}
}
} else {
//
// ROI
//
// checks with roi
final boolean w00Roi = !(roiIter.getSample(xint, yint, 0) > 0);
final boolean w01Roi = !(roiIter.getSample(xint + 1, yint, 0) > 0);
final boolean w10Roi = !(roiIter.getSample(xint, yint + 1, 0) > 0);
final boolean w11Roi = !(roiIter.getSample(xint + 1, yint + 1, 0) > 0);
if (w00Roi && w01Roi && w10Roi && w11Roi) { // SG should not happen
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = destinationNoDataInt;